AC_INIT([nhttpd], [0.2], [amadigan@gmail.com])
AC_CONFIG_SRCDIR(src/nhttpd.c)

CFLAGS=""

AC_ARG_WITH([internal-expat],
	AS_HELP_STRING([--with-internal-expat], [Use the included expat sources
	rather than the system's installed expat. This is automatic if you do
	not have libexpat.]),
	[ 
	if test "x$withval" == "xyes" ; then
		test_external_expat=no
		config_internal_expat=yes
	elif test "x$withval" != "xno" ; then
		echo Bad option passed for expat
		exit 1
	 fi
	])


AC_LIBLTDL_CONVENIENCE
AC_SUBST(LTDLINCL)
AC_SUBST(LIBLTDL)
AC_LIBTOOL_DLOPEN

AC_CONFIG_AUX_DIR(build-aux)
NH_INIT

AC_LIBTOOL_WIN32_DLL
AC_PROG_LIBTOOL
AC_PROG_CC_C99

AM_CONFIG_HEADER(src/config.h)

MODULES="`ls -1 modules | \
while read line; do
	if test -f modules/$line/Makefile || test -f modules/$line/configure ; then
		echo $line
	fi
done`"

echo Modules: $MODULES

m4_include(modules.m4)

AC_CONFIG_FILES([Makefile src/Makefile include/Makefile include/nhttpd/Makefile
	modules/Makefile modules/default_handler/Makefile skeleton/Makefile])
	
if test "x$test_external_expat" != "xno" ; then
	AC_CHECK_HEADER([expat.h], , [
	config_internal_expat=yes
	test_external_expat=no
	])
fi
	
if test "x$test_external_expat" != "xno" ; then
	AC_CHECK_LIB([expat], [XML_ParserCreate], 
		[ libexpat="-lexpat" ],
		[config_internal_expat=yes])
fi


AC_CONFIG_SUBDIRS(libltdl)

if test "x$config_internal_expat" == "xyes"; then
	echo Using internal libexpat
	libexpat=../expat/libexpat.la
	expatdir=expat
	AC_CONFIG_SUBDIRS([expat])
fi

AC_SUBST(moddir)
AC_SUBST(libexpat)
AC_SUBST(expatdir)
AC_SUBST(MODULES)

AC_OUTPUT